package com.fr.chart.plot;

import com.fr.base.Inter;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.chart.axis.CategoryAxis;
import com.fr.chart.base.equals.Equals;
import com.fr.chart.core.glyph.CategoryAxisGlyph;
import com.fr.chart.core.glyph.DateAxisGlyph;
import com.fr.chart.core.glyph.GanttPlotGlyph;
import com.fr.chart.core.glyph.PlotGlyph;
import com.fr.chart.legend.LegendItem;
import com.fr.chart.legend.LineMarkerIcon;
import com.fr.chart.marker.SquareFilledMarker;
import com.fr.chart.marker.TriangleFilledMarker;
import com.fr.data.ChartData;
import java.awt.Color;
import java.util.Date;

public class GanttPlot extends Plot
{
  private static final long serialVersionUID = 3888739478450011607L;
  public static final String XML_TAG = "GanttPlot";
  private CategoryAxis categoryAxis = new CategoryAxis();
  private CategoryAxis dateAxis = new CategoryAxis();
  private Date currentDay = null;

  public GanttPlot()
  {
    getCategoryAxis().setPosition(2);
    getCategoryAxis().setMainGridColor(new Color(237, 237, 237));
    getCategoryAxis().setMainGridStyle(1);
    getDateAxis().setMainGridColor(new Color(237, 237, 237));
    getDateAxis().setMainGridStyle(1);
    getDateAxis().setMainType(1);
    getDateAxis().setDateAxis(true);
    getDateAxis().setPosition(1);
    setBorderColor(new Color(237, 237, 237));
    setBorderStyle(1);
  }

  public void setDateAxis(CategoryAxis paramCategoryAxis)
  {
    this.dateAxis = paramCategoryAxis;
  }

  public CategoryAxis getDateAxis()
  {
    return this.dateAxis;
  }

  public void setCategoryAxis(CategoryAxis paramCategoryAxis)
  {
    this.categoryAxis = paramCategoryAxis;
  }

  public CategoryAxis getCategoryAxis()
  {
    return this.categoryAxis;
  }

  public PlotGlyph createPlotGlyph(ChartData paramChartData)
  {
    GanttPlotGlyph localGanttPlotGlyph = new GanttPlotGlyph();
    install4PlotGlyph(localGanttPlotGlyph, paramChartData);
    installAxisGlyph(localGanttPlotGlyph, paramChartData);
    return localGanttPlotGlyph;
  }

  public void installAxisGlyph(GanttPlotGlyph paramGanttPlotGlyph, ChartData paramChartData)
  {
    CategoryAxisGlyph localCategoryAxisGlyph = new CategoryAxisGlyph(getCategoryAxis());
    paramGanttPlotGlyph.setCategoryAxisGlyph(localCategoryAxisGlyph);
    int i = 0;
    int j = paramChartData.getCategoryLabelCount();
    while (i < j)
    {
      localCategoryAxisGlyph.addCategoryLabel((paramChartData.getCategoryLabel(i) == null) ? "" : paramChartData.getCategoryLabel(i));
      ++i;
    }
    localCategoryAxisGlyph.setGantt(true);
    DateAxisGlyph localDateAxisGlyph = new DateAxisGlyph(getDateAxis());
    paramGanttPlotGlyph.setDateAxisGlyph(localDateAxisGlyph);
    localDateAxisGlyph.initMinMaxValue(getMinValueFromData(paramChartData), getMaxValueFromData(paramChartData));
  }

  public double getMaxValueFromData(ChartData paramChartData)
  {
    double d = 0.0D;
    int i = paramChartData.getSeriesCount();
    if (i == 5)
      i -= 1;
    for (int j = 0; j < paramChartData.getCategoryLabelCount(); ++j)
      for (int k = 0; k < i; ++k)
      {
        Number localNumber = paramChartData.getValueAt(k, j);
        if (localNumber != null)
          if ((j == 0) && (k == 0))
            d = localNumber.doubleValue();
          else
            d = (localNumber.doubleValue() > d) ? localNumber.doubleValue() : d;
      }
    if (d == getMinValueFromData(paramChartData))
      return (d + 10.0D);
    return d;
  }

  public double getMinValueFromData(ChartData paramChartData)
  {
    double d = 0.0D;
    for (int i = 0; i < paramChartData.getCategoryLabelCount(); ++i)
      for (int j = 0; j < paramChartData.getSeriesCount() - 1; ++j)
      {
        Number localNumber = paramChartData.getValueAt(j, i);
        if (localNumber != null)
          if ((i == 0) && (j == 0))
            d = localNumber.doubleValue();
          else
            d = (localNumber.doubleValue() < d) ? localNumber.doubleValue() : d;
      }
    return d;
  }

  public LegendItem[] createLegendItems(PlotGlyph paramPlotGlyph)
  {
    int i = paramPlotGlyph.getSeriesSize();
    LegendItem[] arrayOfLegendItem = new LegendItem[i - 1];
    if (i > 1)
    {
      arrayOfLegendItem[0] = new LegendItem(Inter.getLocText("ChartF-Gantt-PlanTime"));
      arrayOfLegendItem[0].setLineMarkerIcon(new LineMarkerIcon(new Color(200, 199, 199), 0, new SquareFilledMarker()));
      if (i > 2)
      {
        arrayOfLegendItem[1] = new LegendItem(Inter.getLocText("ChartF-Gantt-RealStart"));
        arrayOfLegendItem[1].setLineMarkerIcon(new LineMarkerIcon(new Color(113, 70, 22), 0, new TriangleFilledMarker()));
        if (i > 3)
        {
          arrayOfLegendItem[2] = new LegendItem(Inter.getLocText("ChartF-Gantt-RealEndTime"));
          arrayOfLegendItem[2].setLineMarkerIcon(new LineMarkerIcon(new Color(122, 190, 108), 0, new TriangleFilledMarker()));
          if (i > 4)
          {
            arrayOfLegendItem[3] = new LegendItem(Inter.getLocText("ChartF-Gantt-Progress"));
            arrayOfLegendItem[3].setLineMarkerIcon(new LineMarkerIcon(new Color(0, 107, 172), 0, new SquareFilledMarker()));
          }
        }
      }
    }
    return arrayOfLegendItem;
  }

  public void setCurrentDay(Date paramDate)
  {
    this.currentDay = paramDate;
  }

  public Date getCurrentDay()
  {
    return this.currentDay;
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("GanttPlot");
    super.writeXML(paramXMLPrintWriter);
    if (this.categoryAxis != null)
      this.categoryAxis.writeXML(paramXMLPrintWriter);
    if (this.dateAxis != null)
      this.dateAxis.writeXML(paramXMLPrintWriter);
    paramXMLPrintWriter.end();
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    super.readXML(paramXMLableReader);
    if (paramXMLableReader.isChildNode())
    {
      String str = paramXMLableReader.getTagName();
      if (str.equals("CategoryAxis"))
        this.categoryAxis = ((CategoryAxis)paramXMLableReader.readXMLObject(new CategoryAxis()));
      if (str.equals("DateAxis"))
        this.dateAxis = ((CategoryAxis)paramXMLableReader.readXMLObject(new CategoryAxis()));
    }
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    GanttPlot localGanttPlot = (GanttPlot)super.clone();
    if (getDateAxis() != null)
      localGanttPlot.setDateAxis((CategoryAxis)this.dateAxis.clone());
    if (this.categoryAxis != null)
      localGanttPlot.categoryAxis = ((CategoryAxis)this.categoryAxis.clone());
    return localGanttPlot;
  }

  public boolean equals(Object paramObject)
  {
    if (!(paramObject instanceof GanttPlot))
      return false;
    GanttPlot localGanttPlot = (GanttPlot)paramObject;
    if (!(super.equals(localGanttPlot)))
      return false;
    if (!(Equals.equals(localGanttPlot.getCategoryAxis(), getCategoryAxis())))
      return false;
    if (!(Equals.equals(localGanttPlot.getDateAxis(), getDateAxis())))
      return false;
    return (Equals.equals(localGanttPlot.currentDay, this.currentDay));
  }
}